package com.maket.jbxx.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.maket.jbxx.domain.CpflProductClassification;
import com.maket.jbxx.service.ICpflProductClassificationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 产品分类Controller
 * 
 * @author ruoyi
 * @date 2024-07-02
 */
@RestController
@RequestMapping("/classification")
public class CpflProductClassificationController extends BaseController
{
    @Autowired
    private ICpflProductClassificationService cpflProductClassificationService;

    /**
     * 查询产品分类列表
     */
    @RequiresPermissions("jbxx:classification:list")
    @GetMapping("/list")
    public TableDataInfo list(CpflProductClassification cpflProductClassification)
    {
        startPage();
        List<CpflProductClassification> list = cpflProductClassificationService.selectCpflProductClassificationList(cpflProductClassification);
        return getDataTable(list);
    }

    /**
     * 导出产品分类列表
     */
    @RequiresPermissions("jbxx:classification:export")
    @Log(title = "产品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CpflProductClassification cpflProductClassification)
    {
        List<CpflProductClassification> list = cpflProductClassificationService.selectCpflProductClassificationList(cpflProductClassification);
        ExcelUtil<CpflProductClassification> util = new ExcelUtil<CpflProductClassification>(CpflProductClassification.class);
        util.exportExcel(response, list, "产品分类数据");
    }

    /**
     * 获取产品分类详细信息
     */
    @RequiresPermissions("jbxx:classification:query")
    @GetMapping(value = "/{cpflCode}")
    public AjaxResult getInfo(@PathVariable("cpflCode") String cpflCode)
    {
        return success(cpflProductClassificationService.selectCpflProductClassificationByCpflCode(cpflCode));
    }

    /**
     * 新增产品分类
     */
    @RequiresPermissions("jbxx:classification:add")
    @Log(title = "产品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CpflProductClassification cpflProductClassification)
    {
        return toAjax(cpflProductClassificationService.insertCpflProductClassification(cpflProductClassification));
    }

    /**
     * 修改产品分类
     */
    @RequiresPermissions("jbxx:classification:edit")
    @Log(title = "产品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CpflProductClassification cpflProductClassification)
    {
        return toAjax(cpflProductClassificationService.updateCpflProductClassification(cpflProductClassification));
    }

    /**
     * 删除产品分类
     */
    @RequiresPermissions("jbxx:classification:remove")
    @Log(title = "产品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cpflCodes}")
    public AjaxResult remove(@PathVariable String[] cpflCodes)
    {
        return toAjax(cpflProductClassificationService.deleteCpflProductClassificationByCpflCodes(cpflCodes));
    }
}
